<?php
/**
 * 微博后台管理项目 媒体表数据层

 */

define("MBLOG_USER_RT","mblog_user_rt_");

class db_mblog_user_rt extends db_base
{
	var $table_name  ="mblog_user_rt";
	
	function get_item_by_id($id)
	{
		
		$key = MBLOG_USER_RT . "-get_item_by_id-{$id}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = " id = '{$id}' ";
			$content = $this->get_alllist($this->table_name,1,1, "", $where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}
		return $content[0];
		
	}
	
	function get_user_rt_list_by_uid($uid,$p=1,$pcount=20)
	{
		$key = MBLOG_USER_RT . "-get_user_rt_list_by_uid-{$uid}-{$p}-{$pcount}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = " uid = '{$uid}' and status =1  ";
			$content = $this->get_alllist($this->table_name,$p,$pcount, "id desc", $where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	function get_user_rt_count_by_uid($uid)
	{
		$key = MBLOG_USER_RT . "-get_user_rt_count_by_uid-{$uid}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = " uid = '{$uid}' and status =1  ";
			$content = $this->get_listcount($this->table_name,$where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	function get_user_rt_count_by_mid($mid)
	{
		$key = MBLOG_USER_RT . "-get_user_rt_count_by_mid-{$mid}";
		$mc = mem_cache::get_instance();
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = " uid = '{$mid}' and status =1  ";
			$content = $this->get_listcount($this->table_name,$where);
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_10);
		}
		else
		{
			$content = unserialize($cache);
		}

		return $content;
	}
	
	
	function insert_mblog_user_rt($uid,$mid,$link)
	{
		$ary = array();
		$ary["uid"] = $uid;
		$ary["mid"] = $mid;
		$ary["link"] = $link;
		
		$ary["status"] = 1;
		$ary["create_time"] = Date::get_date_time();
		
		$res = $this->insert($this->table_name,$ary,"",true);
		
		
		return $res;
	}
	
	function update_mblog_user_rt_by_id($id,$status="")
	{
		
		if(strlen($status) > 0) $ary["status"] = "{$status}";
		
		$where = "id = {$id}";
		
		$res = $this->update($this->table_name,$ary,$where);
		
		
		return $res;
	}
	
	
	
}
